Skip to content

Build macOS prebuilts for arm64 and x86_64#2601

Open
yyy-amnezia wants to merge 9 commits into
devfrom
feat/macos-arm64-non-ne
Open

Build macOS prebuilts for arm64 and x86_64#2601
yyy-amnezia wants to merge 9 commits into
devfrom
feat/macos-arm64-non-ne

Conversation

@yyy-amnezia
Copy link
Copy Markdown
Collaborator

No description provided.

@yyy-amnezia yyy-amnezia requested a review from ygurov May 14, 2026 11:38
@yyy-amnezia yyy-amnezia force-pushed the feat/macos-arm64-non-ne branch from 961b231 to 1605667 Compare May 14, 2026 15:36
Copy link
Copy Markdown
Collaborator

@ygurov ygurov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments for a single recipe though to be applied for all modified recipes

Comment thread recipes/awg-go/conanfile.py Outdated
return self.settings.get_safe("os.version")

def _go_env(self, goarch):
env = Environment()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use Environment manually, or not as a main one - it ignores externally-specified flags and Conan internals passing to the Makefile.

Use an env on a top of this one instead

tc = AutotoolsToolchain(self)
env = tc.environment()

Comment thread recipes/awg-go/conanfile.py Outdated
env = Environment()
env.define("GOOS", self._goos)
env.define("GOARCH", goarch)
env.define("GOROOT", self.dependencies.build["go"].package_folder)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not specify GOROOT - it does not change the actual go executable used, just replaces the toolchain location.
I see we have issues with passing our external go in here, so let's use this one as a first line in def generate(self). Should resolve the issue

VirtualBuildEnv(self).generate()

Comment thread recipes/awg-go/conanfile.py Outdated
env.define("GOARCH", goarch)
env.define("GOROOT", self.dependencies.build["go"].package_folder)
env.define("GOPATH", os.path.join(self.build_folder, "gopath"))
env.define("GOMODCACHE", os.path.join(self.build_folder, "gopath", "pkg", "mod"))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, specifying this one is not a bad idea!
Let's do it for all platforms, should make builds more consistent

Comment thread recipes/awg-go/conanfile.py Outdated
return env

def _cgo_arch_flags(self, goarch):
return f"-arch {self._clang_arch_map[goarch]}"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-arch option used in here allows values in apple-clang-internal format, not the golang one.
These values are corresponding with the ones used in Conan, so let's just use them

Moreover, Conan does specify multiple -arch flags itself during generate step if AutotoolsToolchain is used.

Comment thread recipes/awg-go/conanfile.py Outdated
env.define("GOCACHE", os.path.join(self.build_folder, "gocache"))
env.define("GOTELEMETRY", "off")
if self._macos_deployment_target:
env.define("MACOSX_DEPLOYMENT_TARGET", self._macos_deployment_target)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one would be specified automatically if AutotoolsToolchain is used. I would suggest just make a proper generate step instead of applying every flag manually

Comment thread recipes/awg-go/conanfile.py Outdated
env.define("GOTELEMETRY", "off")
if self._macos_deployment_target:
env.define("MACOSX_DEPLOYMENT_TARGET", self._macos_deployment_target)
env.prepend_path("PATH", self._go_bin_path)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread recipes/awg-go/conanfile.py Outdated
def _cgo_arch_flags(self, goarch):
return f"-arch {self._clang_arch_map[goarch]}"

def _build_go_arch(self, goarch):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY
Let's use an existing build step iterating all over archs, and use lipo then

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have a complaint about the building process - there should be a single function which does the job.
I find trying to put something into the hooks a very bad practice. Recipe becomes unclear to read and analyze in the future
DRY KISS

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is still unresolved

Comment thread recipes/awg-go/conanfile.py Outdated
env.define("CGO_CFLAGS", self._cgo_arch_flags(goarch))
env.define("CGO_LDFLAGS", self._cgo_arch_flags(goarch))
with env.vars(self).apply():
self.run("make", env=None)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not run make manually, use

at = Autotools(self)
at.make()

Otherwise, it would ignore all Conan internal-specified variables

@yyy-amnezia yyy-amnezia force-pushed the feat/macos-arm64-non-ne branch 2 times, most recently from c079e7f to 91cc9f1 Compare May 16, 2026 09:15
@yyy-amnezia yyy-amnezia force-pushed the feat/macos-arm64-non-ne branch from 91cc9f1 to d1c6cd4 Compare May 19, 2026 12:38
@ygurov ygurov force-pushed the feat/macos-arm64-non-ne branch 4 times, most recently from ca4a82a to 966c9c6 Compare May 25, 2026 08:10
@yyy-amnezia yyy-amnezia force-pushed the feat/macos-arm64-non-ne branch from 966c9c6 to 6e7925b Compare May 26, 2026 13:21
Copy link
Copy Markdown
Collaborator

@ygurov ygurov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again, reviewed just a single recipe, but to be applied for every changed one

Comment thread client/CMakeLists.txt Outdated

if(APPLE AND NOT IOS AND NOT MACOS_NE)
set(SIGN_OVPN_SCRIPT [=[
if [ "$CODE_SIGNING_ALLOWED" != "NO" ]; then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a huge hack that should be avoided at any cost - very fragile and non-transparent.
You can review the process of signing the binary from CPack cmake code, there should be more appropriate place for the code

Comment thread recipes/awg-go/conanfile.py Outdated
def _cgo_arch_flags(self, goarch):
return f"-arch {self._clang_arch_map[goarch]}"

def _build_go_arch(self, goarch):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have a complaint about the building process - there should be a single function which does the job.
I find trying to put something into the hooks a very bad practice. Recipe becomes unclear to read and analyze in the future
DRY KISS

Comment thread recipes/awg-go/conanfile.py Outdated
env.define(name, value)

def _go_arch_make_args(self, goarch):
return [f"{name}={value}" for name, value in self._go_cache_vars().items()] + [
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a slope. Why don't we just add them by env.define() calls?
Complex logic is not what we want here
KISS

Comment thread recipes/awg-go/conanfile.py Outdated
}

def _define_go_cache_env(self, env):
for name, value in self._go_cache_vars().items():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for here. Why do we need all of those abstractions if we can define those vars in place at generate() stage?
KISS

Comment thread recipes/awg-go/conanfile.py Outdated
)

def generate(self):
VirtualBuildEnv(self).generate()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All recipes have virtualbuildenv by default, if it's not turned off explicitly. Redundant; safe to remove

Comment thread recipes/awg-go/conanfile.py Outdated

def _build_go_arch(self, goarch):
autotools = Autotools(self)
autotools.make(args=self._go_arch_make_args(goarch))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subsequent calls of make with different arch could lead to UB. Make sure it's cleared or build in separate folders

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one as well

Comment thread recipes/tun2socks/conanfile.py Outdated
return str(self.settings.os) == "Macos" and len(self._archs) > 1

@property
def _is_unsupported_multi_arch(self):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Property is overkill, could be inlined. KISS

Comment thread client/CMakeLists.txt Outdated
set(MACOS_CODE_SIGN_FLAGS "--deep")
endif()
set_target_properties(${PROJECT} PROPERTIES
XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "${MACOS_CODE_SIGN_FLAGS}"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Macos build could be assembled using not only the Xcode generator. I find this one an unreliable thing

Comment thread client/CMakeLists.txt Outdated
MACOSX_PACKAGE_LOCATION MacOS
)
target_sources(${PROJECT} PRIVATE ${MACOS_OVPN_SCRIPT})
if(BUILD_VPN_KEYCHAIN)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we sign something during build? Please consider doing that in CPack as I mentioned previously. Or let's discuss that if you do not agree

Comment thread recipes/awg-go/conanfile.py Outdated
def _cgo_arch_flags(self, goarch):
return f"-arch {self._clang_arch_map[goarch]}"

def _build_go_arch(self, goarch):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is still unresolved

Comment thread recipes/awg-go/conanfile.py Outdated

def _build_go_arch(self, goarch):
autotools = Autotools(self)
autotools.make(args=self._go_arch_make_args(goarch))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one as well

Comment thread client/CMakeLists.txt Outdated
${OVPN_SCRIPTS}
"$<TARGET_FILE_DIR:${PROJECT}>"
)
if(NOT APPLE)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume on Apple it should be copied as well

Comment thread client/CMakeLists.txt Outdated

if (APPLE AND NOT IOS AND NOT MACOS_NE)
list(APPEND OVPN_SCRIPTS "${CMAKE_SOURCE_DIR}/deploy/data/macos/update-resolv-conf.sh")
set(MACOS_OVPN_SCRIPT "${CMAKE_SOURCE_DIR}/deploy/data/macos/update-resolv-conf.sh")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this change? :D
Looks like we use an additional variable to store a single string in the list

Comment thread recipes/awg-go/conanfile.py Outdated
for goarch in self._goarchs:
arch_build_folder = os.path.join(self.build_folder, f"build-{goarch}")
rmdir(self, arch_build_folder)
copy(self, "*", src=self.source_folder, dst=arch_build_folder, excludes=(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks complicated and untrivial.
I would suggest to use DESTDIR variable of the original Makefile

Comment thread recipes/awg-go/conanfile.py Outdated
))

at = Autotools(self)
with chdir(self, arch_build_folder):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one ain't gonna work. To execute Makefile you have to be in the same directory with it, or use -C option. The 2nd could produce unexpected output

Comment thread recipes/awg-go/conanfile.py Outdated
env.define("GOOS", self._goos)
env.define("GOARCH", self._goarch)
if not self._is_universal_macos:
env.define("GOARCH", self._goarch)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already define one in Makefile call itself. I do not think the extra one is required

Comment thread recipes/awg-go/conanfile.py Outdated
at = Autotools(self)
with chdir(self, arch_build_folder):
at.make(args=[
f"GOOS={self._goos}",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think multi-os bundles are possible :)
Let's stick with the only one defined in env

Comment thread recipes/awg-go/conanfile.py Outdated
tc.generate(env)

def build(self):
if self._is_universal_macos:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still special handling in here.
Let's use a unified way to compile the binary despite the fact it is multiarch. The only difference is the merging thingy made by lipo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants